package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ap0stoL2
 * Date: 2023-07-24
 * Time: 9:17
 */
//线程终止(手动标志位)
public class Demo8 {

    public  static  boolean OK=false;//标志位

    public static void main(String[] args) throws InterruptedException {

        //final boolean OK=false;//标志位
        Thread t = new Thread( ()->{
            while(!OK){
                System.out.println(" i am thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        //主线程运行一段时间让线程t结束
        System.out.println("5s after,end");
        Thread.sleep(5000);
        //修改标志位,让线程结束
        System.out.println("线程终止");
        OK=true;

    }
}
